/*
  Copyright 2006 by Lukas Loehrer

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

  Author: Lukas Loehrer <loehrerl [at] gmx [dot] net>
*/
// Base class for services that emit js-event messages

// Set prototype for base class
var BaseService = module.require("class", "base_service");
var inheritor = new BaseService("foo");

const util = module.require('package', 'mozremote/util');

function constructor(name, remote) {
	BaseService.call(this, name);
	this._remote = remote;
	this._events = {};
}

function _fireEvent(spec, args) {
	var event, _this = this;
	if (!this._events[spec]) {
		return false;
	}
	event = this._remote.makeJSEventMessage(this._serviceName, spec, args);
	util.doLater(function () {
		_this._remote.sendObject(event);
	}, 0);
	return true;
}


function listAvailableEvents(enabledOnly) {

}

function enableEvent(spec) {
	// TODO: maybe allow for spec to be a regexp
	if (spec in this._events) {
		this._events[spec] = true;
		return true;
	}
	return false;
}

function disableEvent(spec) {
	if (spec in this._events) {
		this._events[spec] = false;
		return true;
	}
	return false;
}
